package com.fzdy.dataplatform.entity;

import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;

import javax.persistence.*;
import java.util.Date;

@Entity
@Table(name = "device")
@Data
public class Device {
    @Id
    @Column(name = "sn", updatable = true)
    private String sn;
    @Column(name = "name")
    private String name;
    @Column(name = "businessid", insertable = false, updatable = false)
    private Integer businessid;
    @Column(name = "imsi")
    private String imsi;
    @Column(name = "imei")
    private String imei;
    @Column(name = "sim")
    private String sim;
    @Column(name = "info")
    private String info;
    @Column(name = "coordinate")
    private String coordinate;
    @Column(name = "location")
    private String location;
    @Column(name = "status")
    private Integer status;
    @Column(name = "netwayid", insertable = false, updatable = false)
    private Integer netwayid;
    @Column(name = "privateprotocol")
    private Integer privateProtocol;
    @Column(name = "createdate")
    private Date createdate;
    @Column(name = "coapdeviceid")
    private String coapdeviceid;
    @Column(name = "coappsk")
    private String coappsk;

    @JSONField(serialize = false)
    @ManyToOne
    @JoinColumn(name = "netwayid", referencedColumnName = "id", foreignKey = @ForeignKey(name = "device_ibfk_1"))
    private NetWay netway;
    @JSONField(serialize = false)
    @ManyToOne
    @JoinColumn(name = "businessid", referencedColumnName = "id", foreignKey = @ForeignKey(name = "device_ibfk_2"))
    private Business business;
    @JSONField(serialize = false)
    @OneToOne(mappedBy = "device")
    private DeviceOwner deviceOwner;

    public void GeneralParams(String name, String imsi, String imei, String sim, String info, String coordinate,
                              String location) {
        if (name==null){
            this.name=this.sn;
        }else {
            this.name = name;
        }
        this.imsi = imsi;
        this.imei = imei;
        this.sim = sim;
        this.info = info;
        this.coordinate = coordinate;
        this.location = location;

    }

}
